package com.example.tms.mapper;


import com.example.tms.bean.RoadInfo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 线路信息
 */
@Repository
public interface RoadMapper extends JpaRepository<RoadInfo,String> {

    //查询线路信息（线路id）
    @Query(value = "select * from road_info where xlid = ?1 and sfcz = true", nativeQuery = true)
    RoadInfo findByXlid(String xlid);

    List<RoadInfo> findBySfczOrderByLasttimeAsc(Boolean sfcz);

    //查询线路信息（区域id）
    @Query(value = "select * from road_info where qyid = ?1 and sfcz = true", nativeQuery = true)
    List<RoadInfo> findByQyid(String qyid);

    //查询线路信息（线路助记码）
    RoadInfo findByXlzjmAndSfcz(String xlzjm, boolean sfcz);

    //查询线路信息（线路编码）
    RoadInfo findByXlbmAndSfcz(String xlbm, boolean sfcz);

    //删除线路信息（假删除 线路id）
    @Query(value = "update road_info set sfcz = false where xlid = ?1", nativeQuery = true)
    @Modifying
    @Transactional
    void DeleteByXlid(String xlid);

    //查询线路名称（线路名称）
    RoadInfo findByXlmcAndSfcz(String xlmc,boolean sfcz);

    RoadInfo findByXlidAndSfcz(String xlid, boolean sfcz);
}